/*
 * @copyright IMTT. Co. Ltd.
 * 
 * Here is detailed comment.
 */
package com.apis.web.goods;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.apis.bussiness.entity.impl.GoodsImpl;
import com.apis.bussiness.entries.impl.GoodsMgrImpl;
import com.apis.web.Action;
import com.apis.web.WebConstants;
import com.apis.web.XmlResponse;


/**
 * @author LiHongChun
 * @date 2012-10-25
 * @copyright IMTT. Co. Ltd.
 */
public class GetGoods extends Action {

	/* (non-Javadoc)
	 * @see com.imtt.insect.web.Action#execute(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void execute(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
		XmlResponse xml = new XmlResponse();
		xml.setRequest(Request(req));
		Integer id = Integer.parseInt( req.getParameter(WebConstants.TAG_GOODS_ID) );
		if (id == null) {
			String reason = "操作失败: 缺少必要信息导致当前操作失败...";
			xml.setReason(reason);
		} else {
			GoodsMgrImpl manager = new GoodsMgrImpl();
			try {
				StringBuilder sb = new StringBuilder();
				GoodsImpl temp = (GoodsImpl) manager.get(GoodsImpl.class, id);
				sb.append("<goods>");
				sb.append("<"+ WebConstants.TAG_GOODS_ID +">").append(temp.getId()).append("</"+ WebConstants.TAG_GOODS_ID +">");
				sb.append("<"+ WebConstants.TAG_GOODS_NAME +">").append(temp.getName()).append("</"+ WebConstants.TAG_GOODS_NAME +">");
				sb.append("<"+ WebConstants.TAG_GOODS_CODE +">").append(temp.getCode()).append("</"+ WebConstants.TAG_GOODS_CODE +">");
				sb.append("<"+ WebConstants.TAG_GOODS_PRICE +">").append(temp.getPrice()).append("</"+ WebConstants.TAG_GOODS_PRICE +">");
				sb.append("</goods>");
				xml.setData(sb.toString());
				xml.setState(1);
				sb = null;
			} catch (Exception e) {
				String reason = "操作失败: 不存在与此ID对应的公司信息...";
				xml.setReason(reason);
				xml.setException(e);
			}
		}

		Response(resp, xml.toString());
	}

	/* (non-Javadoc)
	 * @see com.imtt.insect.web.Action#getActionID()
	 */
	@Override
	public int getActionID() {
		// TODO Auto-generated method stub
		return 1004;
	}

}
